﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Libs.Db;


namespace Libs.ViettelSMS
{
    public class MT
    {
        public int MTID { get; set; }
        public string PhoneNumber { get; set; }
        public string Content { get; set; }
        public int Status { get; set; }
        public DateTime SendTime { get; set; }
        public string PartnerCode { get; set; }
        public DateTime CreatedTime { get; set; }
        public string Message { get; set; }
        public int ReturnValue { get; set; }

        public MT()
        {

        }

        ~MT()
        {

        }

        public virtual void Dispose()
        {

        }

        /// <summary>
        /// Thêm mới Account
        /// </summary>
        public void Add()
        {
            DbHelper db = new DbHelper(Config.ViettelSMSConnectionStrings);
            SqlParameter[] pars = new SqlParameter[7];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@PhoneNumber", PhoneNumber);
            pars[2] = new SqlParameter("@Content", Content);
            pars[3] = new SqlParameter("@Status", Status);
            pars[4] = new SqlParameter("@SendTime", SendTime);
            pars[5] = new SqlParameter("@PartnerCode", PartnerCode);
            pars[6] = new SqlParameter("@Message", Message);

            db.ExecuteNonQuerySP("sp_MT_Insert", pars);
            MTID = Convert.ToInt32(pars[0].Value);
        }

        /// <summary>
        /// Cập nhật Account
        /// </summary>
        public void Update()
        {
            DbHelper db = new DbHelper(Config.ViettelSMSConnectionStrings);
            SqlParameter[] pars = new SqlParameter[5];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@MTID", MTID);
            pars[2] = new SqlParameter("@Status", Status);
            pars[3] = new SqlParameter("@SendTime", SendTime);
            pars[4] = new SqlParameter("@Message", Message);

            db.ExecuteNonQuerySP("sp_MT_Update", pars);
            ReturnValue = Convert.ToInt32(pars[0].Value);
        }

        public List<MT> ListSend()
        {
            DbHelper db = new DbHelper(Config.ViettelSMSConnectionStrings);
            return db.GetListSP<MT>("sp_MT_SelectListSend");
        }

    }
}
